import requests
import json
proxy = {
    'http':'127.0.0.1:8888'
}

def pretty_print_response(res):
    print(
        '{}\nHTTP/1.1 {}\n{}\n\n{}'.format(
        '\n\n----------- 得到响应 -----------',
        res.status_code,
        '\n'.join('{}: {}'.format(k, v) for k, v in res.headers.items()),
        res.text
    ))



dict1 = {
    'name':'caipeiyan',
    'age':12
}
dict2 = {
    'pagesize':12,
    'di':1
}
str1 = '你好'
# 这里要docker启动这个项目
# rs = requests.post('http://127.0.0.1:8082/post',params=dict1,data=str1.encode('utf8'),proxies=proxy)
# rs = requests.post('http://127.0.0.1:8082/post',params=dict1,data=dict2,proxies=proxy)
# rs = requests.post('http://127.0.0.1:8082/post',params=dict1,data=json.dumps(dict2),proxies=proxy)
# rs = requests.post('http://127.0.0.1:8082/post',params=dict1,json=dict2,proxies=proxy)
# pretty_print_response(rs)


files = {
    'file':open('/Users/show/Downloads/编程/python学习/wenben.txt','rb')
}
# r = requests.post('http://127.0.0.1:80/',files = files,proxies=proxy)
# pretty_print_response(r)

dict1 = {
    'cookie':'sessionid=1998'
}
dict2 = {
    'seesionid':'1998'
}

# requests.post('http://127.0.0.1:80/post',headers = dict1,params={'id':1},proxies=proxy)
# requests.post('http://127.0.0.1:80/post',cookies = dict2,params={'id':2},proxies=proxy)

# req = requests.Request('POST','http://127.0.0.1:8082/post',headers = dict1,params={'id':1},proxies=proxy)


def print_url(r, *args, **kwargs):
    print(f'我是响应内容，我执行了hook，我打印：{r.url}')

def record_hook(r, *args, **kwargs):
    r.hook_called = True
    return r

r = requests.get('http://127.0.0.1:80/get',hooks={'response':[print_url,record_hook]})
pretty_print_response(r)
print(r.hook_called)
